/****************************************************************************/
/***                                                                      ***/
/***   (C) 2012-2014 Dierk Ohlerich et al., all rights reserved.          ***/
/***                                                                      ***/
/***   Released under BSD 2 clause license, see LICENSE.TXT               ***/
/***                                                                      ***/
/****************************************************************************/

mtrl NullGeometryShader 
{
  struct ia2vs
  {
    float3 pos : POSITION;
    float3 norm : NORMAL;
    float2 uv0 : TEXCOORD0;
  };
  struct vs2gs
  {
    float4 tpos : POSITION;
    float2 uv0 : TEXCOORD0;
    float3 pos : TEXCOORD1;
  };
  struct gs2ps
  {
    float4 tpos : SV_Position;
    float4 color : COLOR;
    float2 uv0 : TEXCOORD0;
  };

  cbuffer cbvs : vs(0) : register(0)
  {
    row_major float4x4 mat;
  };
  cbuffer cbgs : gs(0) : register(0)
  {
    float3 ldir;
  };
  
  vs hlsl5
  {
    void main(in ia2vs i,out vs2gs o)
    {
      o.tpos = mul(mat,float4(i.pos.xyz,1));
      o.uv0 = i.uv0;
      o.pos = i.pos;
    }
  };
  gs hlsl5
  {
    [maxvertexcount(3)]
    void main(triangle vs2gs i[3],inout TriangleStream<gs2ps> os)
    {
      gs2ps o;
 
      float3 da = i[0].pos - i[1].pos;
      float3 db = i[0].pos - i[2].pos;
      float3 norm = normalize(cross(da,db));
      float4 color = max(dot(ldir,norm),0.0)*0.75+0.125;

      for(int n=0;n<3;n++)
      {
        o.tpos = i[n].tpos;
        o.color = color;
        o.uv0 = i[n].uv0;
        os.Append(o);
      }
      os.RestartStrip();
    }
  };
  ps hlsl5
  {
    void main(in gs2ps i,out float4 r:SV_Target)
    {
      r = i.color;
    }
  };
} 
/****************************************************************************/
